package com.itheima.dao.system;

import com.itheima.domain.system.Role;
import com.itheima.domain.system.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface RoleDao {
    //查询所有Role
    @Select("select * from ss_role")
   List<Role> findAll();

    //添加Role
    @Insert("insert into ss_role (role_id,name,remark) values (#{roleId},#{name},#{remark})")
    void addRole(Role role);

    //修改Role
    @Update("update ss_role set role_id=#{roleId},remark=#{remark},name=#{name} where role_id=#{roleId}")
    void updateRole(Role role);

    //删除Role
    @Delete("delete from ss_role where role_id=#{id}")
    void deleteRole(@Param("id") String id);

    //通过id查询Role
    @Select("select * from ss_role where role_id=#{id}")
    Role findRoleById(@Param("id") String id);

    @Select("select module_id as id,parent_id as pId,name as name, case when module_id in (select module_id from ss_role_module where role_id=#{roleId}) then 'true' else 'false' end as checked from ss_module")
    List<Map> findAuthorDataByRid(@Param("roleId") String roleId);

    //配置根据roleId删除关系表数据
    @Delete("delete from ss_role_module where role_id=#{roleId}")
    void deleteRoleModule(@Param("roleId") String roleId);

    //配置全字段插入，当某个字段没有值时，插入null
    @Insert("insert into ss_role_module (role_id,module_id) values (#{roleId},#{moduleId})")
    void saveRoleModule(@Param("roleId") String roleId,
                     @Param("moduleId") String moduleId);
}
